#!/bin/bash

basedir=/home/sunshine

tooldir=$basedir/fastsheep/tool

if [ "$tooldir" != $(pwd) ]; then
    echo "Error,you have to run this shell in proper folder!"
    exit 1
fi

configure=$tooldir/conf

getconf()
{
    cat $configure | grep $1 | cut -d ':' -f 2
}

username=$(getconf username)
ipaddress=$(getconf ipaddress)
remotedir=$(getconf remotedir)

cd $basedir

tar \
--exclude=fastsheep/tool \
--exclude=fastsheep/*.md \
--exclude=fastsheep/.git \
--exclude=fastsheep/.gitignore \
-zcvf $tooldir/fastsheep.tar.gz fastsheep

cd $tooldir
scp fastsheep.tar.gz $username@$ipaddress:$remotedir/
rm fastsheep.tar.gz


if [ $? != 0 ]; then
    echo "error,Please check!"
else
    echo "success"
    exit 0
fi
